package com.imooc.security.core.validate.code;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.imooc.security.core.properties.SecurityProperties;

/**
 * @ClassName ValidateBeanConfig.java
 * @Description 可配置bean，配置验证码生成逻辑
 * @author Jon
 * @date 2018年6月1日 下午2:49:34
 */
@Configuration
public class ValidateBeanConfig {
	@Autowired
	private SecurityProperties securityProperties;
	
	//系统初始化此bean之前会先寻找是否有imageCodeGenerator这个bean，如果有则不执行此bean，直接用已经初始化的名字为imageCodeGenerator的bean
	@Bean
	@ConditionalOnMissingBean(name="imageCodeGenerator")
	public ValidateCodeGenerator imageCodeGenerator() {
		ImageCodeGenerator codeGenerator = new ImageCodeGenerator();
		codeGenerator.setSecurityProperties(securityProperties);
		return codeGenerator;
	}
}
